﻿<?php
session_start();

require_once "config.php";
require_once "db.class.php";
require_once "server.class.php";

$params = array("host"=>"$host", "user"=>"$user", "pass"=>"$pass", "db"=>"$db");
$db = new Dbclass($params, false);
$server = new ServerHelperClass($db, $tables);

$renrenId = $_POST['xn_sig_user'];

//Authon with Renren
if ($server->generate_sig($_POST, $rrSecret) != $_POST['xn_sig'])
{
	/*
	ksort($_POST);
	foreach ($_REQUEST as $k=>$v)
	{
		$sql = "insert into debug (value1, value2) values ('".$k."', '".$v."')";
		$result = $db->query($sql);
	}
	$sql = "insert into debug (value1, value2) values ('md5', '".$server->generate_sig($_POST, $rrSecret)."')";
	$result = $db->query($sql);
	 */
	die("fail!");
}
else if ($_POST['xn_sig_authorize'] == 1)
{
	$userId = $server->getUserId($renrenId);
	if (!$userId)
	{
		$userId = $server->createUser($renrenId);
	}
}

$db->close();

?>
